package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.dao.impl.UserDaoImpl;
import com.itheima.domain.User;
import com.itheima.service.UserService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService {

    UserDao dao = new UserDaoImpl();

    @Override
    public boolean Register(User user) {
        boolean flag = false;
        try {
            flag = dao.Register(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public User login(User user) {
        User user1 = null;
        try {
            user1 = dao.login(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return user1;
    }

    @Override
    public List<User> findAllUser() {
        List<User> allUser = null;
        try {
            allUser = dao.findAllUser();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return allUser;
    }

    @Override
    public boolean addUser(User user) {
        boolean flag = false;
        try {
            flag = dao.addUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public User findById(String id) {
        User user = null;
        try {
            user = dao.findById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }

    @Override
    public boolean update(User user) {
        boolean flag = false;
        try {
            flag = dao.update(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean deleteById(String id) {

        boolean flag= false;
        try {
            flag = dao.deleteById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }


}
